#include<bits/stdc++.h>
using namespace std;

class Solution {
public:
    int balancedStringSplit(string s) {
        int a[2] = {0, 0};
        int ans = 0;
        for(int i = 0; i < s.length(); i++){
            if(s[i] == 'R')a[0]++;
            else a[1]++;
            if(a[0] == a[1])ans++;
        }
        return ans;
    }
};